package cn.com.ddapp.ddm.adapter;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.zhy.autolayout.AutoLinearLayout;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import cn.com.ddapp.ddm.R;
import cn.com.ddapp.ddm.bean.mine.InformationEntity;

/**
 * Created by Administrator on 2016/8/30.
 */
public class InfoCenterAdapter extends BaseAdapter {

    private Context context;
    private List<InformationEntity.ListBean> list;
    //横竖屏
    int orientation;
    DisplayMetrics dm;
//    private List<Information> list;

    /*public InfoCenterAdapter(Context context, List<Information> list) {
        this.context = context;
        this.list = list;
    }*/
    public InfoCenterAdapter(Context context, List<InformationEntity.ListBean> list,int orientation,DisplayMetrics dm) {
        this.context = context;
        this.list = list;
        this.orientation = orientation;
        this.dm = dm;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_info_center, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (orientation==0||orientation==2){
            int screenWidth = dm.widthPixels;
            int screenHeigh = dm.heightPixels;
            ViewGroup.LayoutParams params = holder.infoL.getLayoutParams();
            params.height = screenHeigh/9;
            holder.infoL.setLayoutParams(params);
        }
        if (1 == list.get(i).getIfRead()) {
            //1 已读
            holder.unread.setVisibility(View.GONE);
        } else {
            //未读
            holder.unread.setVisibility(View.VISIBLE);
        }
        //设置时间
        holder.time.setText(list.get(i).getCreteTime());
        holder.titleInfo.setText(list.get(i).getTitle());
        return convertView;
    }


    static class ViewHolder {
        @BindView(R.id.iv_unread)
        ImageView unread;
        @BindView(R.id.title_info)
        TextView titleInfo;
        @BindView(R.id.tv_createtime)
        TextView time;
        @BindView(R.id.infoL)
        AutoLinearLayout infoL;
        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

    /*public void addView(List<InformationEntity.ListBean> list) {
        if (list == null || list.size() <= 0) {
            return;
        }
        list.addAll(list);
    }*/

}
